package com.lsy.weizhi2.activity;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.config.MyHeight;
import com.lsy.weizhi2.customview.AppraiseItem;
import com.lsy.weizhi2.mybase.MyBaseActivity;

public class Appraise extends MyBaseActivity implements View.OnClickListener{
    private Context context;
    private com.lsy.weizhi2.mybase.MyTitleView mAppraise_title;
    private AppraiseItem mAppraise_nice;
    private AppraiseItem mAppraise_normal;
    private AppraiseItem mAppraise_fail;
    private TextView mAppraise_tv;
    private TextView mTaidu;
    private RatingBar mRating_1;
    private TextView mTaidu1;
    private RatingBar mRating_2;
    private EditText mAppraise_et;
    private int xx;
    private Handler handler=new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_appraise);
        context=Appraise.this;
        bindViews();
    }

    private void bindViews() {

        mAppraise_title = (com.lsy.weizhi2.mybase.MyTitleView) findViewById(R.id.appraise_title);
        mAppraise_nice = (AppraiseItem) findViewById(R.id.appraise_nice);
        mAppraise_normal = (AppraiseItem) findViewById(R.id.appraise_normal);
        mAppraise_fail = (AppraiseItem) findViewById(R.id.appraise_fail);
        mAppraise_tv = (TextView) findViewById(R.id.appraise_tv);
        mTaidu = (TextView) findViewById(R.id.taidu);
        mRating_1 = (RatingBar) findViewById(R.id.rating_1);
        mTaidu1 = (TextView) findViewById(R.id.taidu1);
        mRating_2 = (RatingBar) findViewById(R.id.rating_2);
        mAppraise_et = (EditText) findViewById(R.id.appraise_et);
        mAppraise_nice.setOnClickListener(this);
        mAppraise_normal.setOnClickListener(this);
        mAppraise_fail.setOnClickListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        xx=0;
        new Thread(new Runnable() {
            @Override
            public void run() {
                ViewTreeObserver vto = mAppraise_title.getViewTreeObserver();
                vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        if (xx < 1) {
                            xx++;
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(mAppraise_title.getLayoutParams());
                                    params.height = MyHeight.ACTIONBAR + MyHeight.MyTitleHeight;
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                        mAppraise_title.setLayoutParams(params);
                                    }
                                }
                            });
                        }
                    }
                });
            }
        }).start();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.appraise_nice:
                hide();
                mAppraise_nice.setImage(R.mipmap.good_02);
                break;
            case R.id.appraise_normal:
                hide();
                mAppraise_normal.setImage(R.mipmap.general_02);
                break;
            case R.id.appraise_fail:
                hide();
                mAppraise_fail.setImage(R.mipmap.poor_02);
                break;
        }
    }

    private void hide(){
        mAppraise_nice.setImage(R.mipmap.good_01);
        mAppraise_normal.setImage(R.mipmap.general_01);
        mAppraise_fail.setImage(R.mipmap.poor_01);
    }
}
